using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Recruiters_savedresumes : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
                     WebConfigurationManager.ConnectionStrings[
                       "RecruitVietnam"].ConnectionString;
        if (Session.Contents["rcuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (!IsPostBack)
            ShowData();
            
        if (Session["rcactivate"].ToString() == "False")
        {             
            literalError.Text = "<img border=0 src='/icons/warning.gif'>You can not search resume, <br>because this account is not approved by management team.";
        }
    }
     
    void ShowData()
    {
        try
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "SPViewSavedResumeSearch";
            cls.ParameterCollection = new string[1] { "@RecruiterID" };
            cls.ValueCollection = new string[1] { 
            Convert.ToString(Session.Contents["rcuserid"]) };
            cls.CommandType = CommandType.StoredProcedure;
            DataTable dataTable = cls.GetDataTable();
            GridViewHelper gridViewHelper = new GridViewHelper();
            gridViewHelper.FillDataTableToGridView(
            dataTable, this.GridView1);

            if (GridView1.Rows.Count >= 1)
                btnDelete.Enabled = true;
            else
                btnDelete.Enabled = false;
        }
        catch (Exception ex)
        {
            literalError.Text = ex.Message;
        }
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Server.Transfer("resumeresult.aspx?indexRow=" + e.RowIndex);
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string searchID = "";
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkSearchID");
            if (checkBox.Checked)
            {
                try
                {
                    searchID +=
                    gridViewRow.Cells[1].Text + ",";
                }
                catch (Exception ex)
                {
                    literalError.Text = ex.Message;
                }
            }

        }
        if (searchID != "")
        {
            searchID = searchID.Substring(0, searchID.Length - 1);
            RecruitVietnam recruitVietnam
                        = new RecruitVietnam();
            recruitVietnam.ConnectionString = connectionString;
            string deleteQuery = 
            "delete from tblRCSavedSearchs "+
            " where searchID in (" + searchID +
            ") and RecruiterID ="
            + Session["rcuserid"].ToString();
            if(recruitVietnam.ExecuteSQL(deleteQuery))
                ShowData();
        }
    }
   
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        GridViewRow gridViewRow = e.Row;
        gridViewRow.Cells[3].Visible =
        gridViewRow.Cells[5].Visible =
        gridViewRow.Cells[7].Visible =
        gridViewRow.Cells[9].Visible =
        gridViewRow.Cells[11].Visible =
        gridViewRow.Cells[13].Visible = 
        gridViewRow.Cells[15].Visible =
        gridViewRow.Cells[17].Visible = false;
        
        if (Session["rcactivate"].ToString() == "False")
        {            
            if (gridViewRow.RowType == DataControlRowType.DataRow)
                {
                Button button = (Button)gridViewRow.FindControl("btnSearch");
                button.Enabled = false;
            }
        }
        
    }

    
}
